<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */

namespace App\Dao;

use App\Kernel\Traits\DaoTrait;
use App\Model\GoodsProperty;

/**
 * 商品 SKU属性 DAO
 *
 * @author 张昊(2396675557@qq.com)
 * @package App\Dao
 */
class GoodsPropertyDao extends Dao
{
    use DaoTrait;
    /**
     * 通过 id 获取 sku属性
     *
     * @param int $id
     * @return mixed
     */
    public function first(int $id)
    {
        $first = GoodsProperty::query()->where('id', $id)->select('title')->first();

        return $first['title'];
    }

    /**
     * Get model.
     *
     * @return string
     */
    public function model(): string
    {
        return GoodsProperty::class;
    }

    /**
     * 获得商品所有属性
     * @param int $goods_id
     * @param int $paginate
     * @return mixed
     */
    public function getPpyById(int $goods_id,int $paginate)
    {
        return GoodsProperty::query()->where('goods_id', $goods_id)->select(['*'])->paginate($paginate);
    }

    /**
     * 检查是否存在
     * @param array $ids
     * @return bool
     */
    public function checkExistByIds(array $ids)
    {
        return GoodsProperty::query()->whereIn('id', $ids)->exists();
    }

    /**
     * 删除多个属性
     * @param array $ids
     * @return int|mixed
     */
    public function deleteByIds(array $ids)
    {
        return GoodsProperty::query()->whereIn('id', $ids)->delete();
    }

}